package com.corechina.apex_osswords.controller;

import com.corechina.apex_osswords.common.Response;
import com.corechina.apex_osswords.domain.dto.CoreWeiXinUserBindAppletsDto;
import com.corechina.apex_osswords.service.ICoreMaintenanceEngineerService;
import com.corechina.apex_osswords.service.ICoreWeiXinUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

/**
 * @program: apex_osswords
 * @description: 微信用户相关访问控制类
 * @author: cc
 * @create: 2022-03-29 10:32
 **/

@Api(tags = "微信用户相关")
@RestController
@RequestMapping("/core/weiXinUser")
public class CoreWeiXinUserController {

    @Autowired
    private ICoreWeiXinUser iCoreWeiXinUser;

    @Autowired
    private ICoreMaintenanceEngineerService iCoreMaintenanceEngineerService;

    @GetMapping("/getOpenId")
    @ApiOperation("微信--获取openId")
    public Response getOpenId(String code) {
        return iCoreWeiXinUser.getOpenId(code);
    }

    @PostMapping("/bindApplets")
    @ApiOperation("微信--绑定小程序")
    public Response bindApplets(@RequestBody CoreWeiXinUserBindAppletsDto coreWeiXinUserBindAppletsDto) {
        return iCoreWeiXinUser.bindApplets(coreWeiXinUserBindAppletsDto);
    }

    @GetMapping("/sendCode")
    @ApiOperation("微信--获取短信验证码")
    public Response sendCode(String tel, Integer userType, HttpSession httpSession) {
        return iCoreWeiXinUser.sendCode(tel, userType, httpSession);
    }

    @ApiOperation("微信--账户登录")
    @GetMapping("/loginByWeiXin")
    public Response loginByWeiXin(String openId) {
        return iCoreWeiXinUser.loginByWeiXin(openId);
    }

    @ApiOperation("获取技术人员列表")
    @GetMapping("/getEngineer")
    public Response getEngineer(Integer pageIndex, Integer pageSize) {
        return iCoreMaintenanceEngineerService.getList(null, null, "0", null, 1, pageIndex, pageSize);
    }

    @ApiOperation("切换企业")
    @PutMapping("/switchoverEnterprise")
    public Response switchoverEnterprise(Integer enterpriseId) {
        return iCoreWeiXinUser.updateLoginEnterprise(enterpriseId);
    }

    @ApiOperation("所属企业列表")
    @GetMapping("/getEnterpriseList")
    public Response getEnterpriseList() {
        return iCoreWeiXinUser.getEnterpriseList();
    }


}
